import  sys

result={}

for line in sys.stdin:
    line=line.strip()
    if len(line)==0:
        continue
    Me,Friends=line.split(':')
    Friend=Friends.split(',')
    result[Me]=Friend

    if len(result)==1:
        continue
    else:
        for i in result[Me]:
            for f in result:
                if i in result[f]:
                    if f<Me:
                        print(f+Me,i)
                    elif f>Me:
                        print(Me+f,i)
